<?php
/**
 * 用户控制器
 */

namespace app\api\controller;

use think\response\Json;
use app\api\service\UserService;
use app\common\validate\UserValidate;
use app\api\exception\ApiServiceException;

class UserController extends ApiBaseController
{

    /**
     * 详情
     *
     * @param UserValidate $validate
     * @param UserService $service
     * @return Json
     */
    public function update(UserValidate $validate, UserService $service): Json
    {
        $check = $validate->scene('api_info')->check($this->param);
        if (!$check) {
            return api_error($validate->getError());
        }

        try {
            $param = [
                'avatar'    =>$this->param['avatar'],
                'nickname'  =>$this->param['nickname'],
            ];
            $service->updateData($this->user['id'],$param);
            return api_success([]);

        } catch (ApiServiceException $e) {
            return api_error($e->getMessage());
        }
    }
}
